package cn.ds.assets.module.assets.dal.mysql.dataQualityRuleTemplate;

import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDate;

import cn.ds.assets.framework.common.pojo.PageResult;
import cn.ds.assets.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.ds.assets.framework.mybatis.core.mapper.BaseMapperX;
import cn.ds.assets.module.assets.dal.dataobject.dataQualityRuleTemplate.BaseDataQualityRuleTemplateDO;
import org.apache.ibatis.annotations.Mapper;
import cn.ds.assets.module.assets.controller.admin.dataQualityRuleTemplate.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * 数据质量规则模板关联 Mapper
 *
 * @author admin
 */
@Mapper
public interface BaseDataQualityRuleTemplateMapper extends BaseMapperX<BaseDataQualityRuleTemplateDO> {

    default PageResult<BaseDataQualityRuleTemplateDO> selectPage(BaseDataQualityRuleTemplatePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BaseDataQualityRuleTemplateDO>()
                .eqIfPresent(BaseDataQualityRuleTemplateDO::getRuleGenre, reqVO.getRuleGenre())
                .eqIfPresent(BaseDataQualityRuleTemplateDO::getRuleType, reqVO.getRuleType())
                .eqIfPresent(BaseDataQualityRuleTemplateDO::getQualityDimension, reqVO.getQualityDimension())
                .eqIfPresent(BaseDataQualityRuleTemplateDO::getRuleTemplateType, reqVO.getRuleTemplateType())
                .eqIfPresent(BaseDataQualityRuleTemplateDO::getRuleTemplateCode, reqVO.getRuleTemplateCode())
                .betweenIfPresent(BaseDataQualityRuleTemplateDO::getCreateTime, reqVO.getCreateTime())
                .likeIfPresent(BaseDataQualityRuleTemplateDO::getTemplateName, reqVO.getTemplateName())
                .inIfPresent(BaseDataQualityRuleTemplateDO::getId,reqVO.getIds())
                .orderByDesc(BaseDataQualityRuleTemplateDO::getId));
    }

    default List<BaseDataQualityRuleTemplateDO> selectList(BaseDataQualityRuleTemplateExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<BaseDataQualityRuleTemplateDO>()
                .eqIfPresent(BaseDataQualityRuleTemplateDO::getRuleGenre, reqVO.getRuleGenre())
                .eqIfPresent(BaseDataQualityRuleTemplateDO::getRuleType, reqVO.getRuleType())
                .eqIfPresent(BaseDataQualityRuleTemplateDO::getQualityDimension, reqVO.getQualityDimension())
                .eqIfPresent(BaseDataQualityRuleTemplateDO::getRuleTemplateType, reqVO.getRuleTemplateType())
                .eqIfPresent(BaseDataQualityRuleTemplateDO::getRuleTemplateCode, reqVO.getRuleTemplateCode())
                .betweenIfPresent(BaseDataQualityRuleTemplateDO::getCreateTime, reqVO.getCreateTime())
                .likeIfPresent(BaseDataQualityRuleTemplateDO::getTemplateName, reqVO.getTemplateName())
                .inIfPresent(BaseDataQualityRuleTemplateDO::getId,reqVO.getIds())
                .orderByDesc(BaseDataQualityRuleTemplateDO::getId));
    }

    @Update("UPDATE assets_data_quality_rule_template SET deleted = 1, update_time = #{deletedTime} WHERE id = #{id}")
    void updateToDelete(@Param("id") Long id, @Param("deletedTime") LocalDateTime deletedTime);
}
